package com.yxkj.syh.app.huarong.activities.home.return_cars;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import androidx.lifecycle.Observer;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.syh.app.basic.base.BaseActivity;
import com.yxkj.syh.app.huarong.BR;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.bean.ReturnCar;
import com.yxkj.syh.app.huarong.constants.ArouterPath;
import com.yxkj.syh.app.huarong.databinding.ActivityReturnCarBinding;
import com.yxkj.syh.app.huarong.views.ReturnCarAppointmentDialog;

/**
 * 回头车
 */
@Route(path = ArouterPath.RETURN_CAR_ACTIVITY)
public class ReturnCarActivity extends BaseActivity<ActivityReturnCarBinding, ReturnCarVM> {
    @Autowired
    long id;

    ReturnCarAppointmentDialog mReturnCarAppointmentDialog;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_return_car;
    }

    @Override
    protected int getViewModelId() {
        return BR.returnCarVM;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        if (id == 0) finish();

        mVDBinding.titleView.setLeftOnClickListener(v -> finish());

        mVDBinding.llCall.setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mViewModel.mldReturnCar.getValue().getDrivingPhone()));
            startActivity(intent);
        });

        mVDBinding.btnAppointment.setOnClickListener(v -> {
            if (mViewModel.mldReturnCar.getValue() != null) {
                if (mReturnCarAppointmentDialog == null) {
                    mReturnCarAppointmentDialog = new ReturnCarAppointmentDialog(ReturnCarActivity.this);
                    mReturnCarAppointmentDialog.setOnClickListener((id, remark) -> {
                        mViewModel.appointment(id, remark);
                    });
                }
                mReturnCarAppointmentDialog.build(mViewModel.mldReturnCar.getValue());
                mReturnCarAppointmentDialog.show();
            }

        });

    }

    @Override
    protected void initData() {
        mViewModel.returnCarInfo(id);
    }

    @Override
    protected void initObservers() {
        super.initObservers();
        mViewModel.mldReturnCar.observe(this, returnCar -> {
        });
    }
}
